package com.xqb.modules.controller.ins;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.InsBusinessLicense;
import com.xqb.modules.service.IInsBusinessLicenseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 营业执照Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/insititution/license")
public class InsBusinessLicenseController extends BaseController
{
    @Autowired
    private IInsBusinessLicenseService insBusinessLicenseService;

    /**
     * 查询营业执照列表
     */
    @PreAuthorize("@ss.hasPermi('insititution:license:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsBusinessLicense insBusinessLicense)
    {
        startPage();
        List<InsBusinessLicense> list = insBusinessLicenseService.selectInsBusinessLicenseList(insBusinessLicense);
        return getDataTable(list);
    }

    /**
     * 导出营业执照列表
     */
    @PreAuthorize("@ss.hasPermi('insititution:license:export')")
    @Log(title = "营业执照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsBusinessLicense insBusinessLicense)
    {
        List<InsBusinessLicense> list = insBusinessLicenseService.selectInsBusinessLicenseList(insBusinessLicense);
        ExcelUtil<InsBusinessLicense> util = new ExcelUtil<InsBusinessLicense>(InsBusinessLicense.class);
        util.exportExcel(response, list, "营业执照数据");
    }

    /**
     * 获取营业执照详细信息
     */
    @PreAuthorize("@ss.hasPermi('insititution:license:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(insBusinessLicenseService.selectInsBusinessLicenseById(id));
    }

    /**
     * 新增营业执照
     */
    @PreAuthorize("@ss.hasPermi('insititution:license:add')")
    @Log(title = "营业执照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsBusinessLicense insBusinessLicense)
    {
        return toAjax(insBusinessLicenseService.insertInsBusinessLicense(insBusinessLicense));
    }

    /**
     * 修改营业执照
     */
    @PreAuthorize("@ss.hasPermi('insititution:license:edit')")
    @Log(title = "营业执照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsBusinessLicense insBusinessLicense)
    {
        return toAjax(insBusinessLicenseService.updateInsBusinessLicense(insBusinessLicense));
    }

    /**
     * 删除营业执照
     */
    @PreAuthorize("@ss.hasPermi('insititution:license:remove')")
    @Log(title = "营业执照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(insBusinessLicenseService.deleteInsBusinessLicenseByIds(ids));
    }
}
